//
//  EmojiAttachment.swift
//  表情键盘
//
//  Created by Jacky Sun on 16/5/27.
//  Copyright © 2016年 syf. All rights reserved.
//

import UIKit


class EmojiAttachment: NSTextAttachment {

    var chs: String?
    
    // 根据表情模型， 转换为字符串
    /// 根据表情模型, 创建表情字符串
    class func imageText(emoticon: Emotion, font: UIFont) -> NSAttributedString{
        
        // 1.创建附件
        let attachment = EmojiAttachment()
        attachment.chs = emoticon.chs
        attachment.image = UIImage(contentsOfFile: emoticon.imgPath!)
        // 设置了附件的大小
        let s = font.lineHeight
        attachment.bounds = CGRectMake(0, -4, s, s)
        
        // 2. 根据附件创建属性字符串
        return NSAttributedString(attachment: attachment)
    }}
